package com.pengtu.service.lucene;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.service.admin.ConveyaManager;
import com.pengtu.service.admin.ReceivedManager;
import com.pengtu.service.app.SystemManager;
import com.pengtu.service.asset.MessageManager;
import com.pengtu.service.project.ProjectManager;
import com.pengtu.utils.web.Struts2Utils;


@Transactional
public class LuceneManager {
	private MessageManager messageManager;
	private SystemManager systemManager;
	private ProjectManager projectManager;
	private ConveyaManager conveyaManager;
	private ReceivedManager receivedManager;
	
	private String luceneIndex;//spring注入，在配置文件中赋予值
	private String startDate;//spring注入，在配置文件中赋予值
	private String endDate;//spring注入，在配置文件中赋予值
	
	public String getLuceneIndex() {
		return luceneIndex;
	}

	public void setLuceneIndex(String luceneIndex) {
		this.luceneIndex = luceneIndex;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	@Autowired
	public void setMessageManager(MessageManager messageManager) {
		this.messageManager = messageManager;
	}

	@Autowired
	public void setSystemManager(SystemManager systemManager) {
		this.systemManager = systemManager;
	}
	
	@Autowired
	public void setProjectManager(ProjectManager projectManager) {
		this.projectManager = projectManager;
	}

	@Autowired
	public void setConveyaManager(ConveyaManager conveyaManager) {
		this.conveyaManager = conveyaManager;
	}

	@Autowired
	public void setReceivedManager(ReceivedManager receivedManager) {
		this.receivedManager = receivedManager;
	}

	/**
	 * 
	 * createIndexByLucene:
	 * 适用:
	 * @param fileClassPath跟路径
	 * @param index存放索引路径
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	public void createIndexByLucene(String fileClassPath,String index){
		messageManager.createIndexByLucene(index);
		systemManager.createIndexByLucene(fileClassPath, index);
		projectManager.createIndexByLucene(index);
		conveyaManager.createIndexByLucene(index);
		receivedManager.createIndexByLucene(index);
	}

	/**
	 * 
	 * searchLucene:
	 * 适用:
     * @param index索引查询的目录
	 * @param keyword关键词
	 * @param startDate开始时间  格式为 yyyyMMdd 例 20111120 
	 * @param endDate结束时间   格式为 yyyyMMdd 例 20111120 
	 * @param type 类型
	 * @exception 
	 * @since  1.0.0
	 */
	public void searchLucene(String keyword,String type) {
		System.out.println("========"+luceneIndex);
		if(type != null && !keyword.equals("") && keyword!= null){
			if(type.equals("news")){
					Struts2Utils.getRequest().setAttribute("newsList", messageManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
				}
			
			if(type.equals("fujian")){
					Struts2Utils.getRequest().setAttribute("fujianList", systemManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
				}
			if(type.equals("project")){
				Struts2Utils.getRequest().setAttribute("projectList", projectManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
			}
			if(type.equals("publish")){
				Struts2Utils.getRequest().setAttribute("publishList", messageManager.SearchPublishByLucene(luceneIndex,keyword,startDate,endDate));
			}
			if(type.equals("rAs")){
				Struts2Utils.getRequest().setAttribute("conveyList", conveyaManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
				Struts2Utils.getRequest().setAttribute("receivedList", receivedManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));		
			}
		}		
		if(type==null || type.equals("")){
			Struts2Utils.getRequest().setAttribute("newsList", messageManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
			Struts2Utils.getRequest().setAttribute("fujianList", systemManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
			Struts2Utils.getRequest().setAttribute("projectList", projectManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
			Struts2Utils.getRequest().setAttribute("publishList", messageManager.SearchPublishByLucene(luceneIndex,keyword,startDate,endDate));
			Struts2Utils.getRequest().setAttribute("conveyList", conveyaManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));
			Struts2Utils.getRequest().setAttribute("receivedList", receivedManager.SearchByLucene(luceneIndex,keyword,startDate,endDate));		
		}
	}

}
